package com.testmanager.testmananger.practiseDemo.taskWork;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;


/**
 * 1.查询日终相关
 * 2.开启日终
 * 3.处理日终异常
 */
@Slf4j
@RestController
@RequestMapping("work")
public class DayEndResource {

    @Autowired
    DayEndConunt dayEndConunt;


    @GetMapping("/getDayInfo")
    public ResponseEntity getDayEndInfo(){


        return  ResponseEntity.ok(dayEndConunt.getDayEnd());
    }

    @GetMapping("/dayAdd")
    public ResponseEntity  dayAdd() throws Exception {

        CompletableFuture future = CompletableFuture.supplyAsync(new Supplier<Object>() {
            @Override
            public Object get() {
                try {
                    dayEndConunt.getDayEnd().dayAdd();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        });

      //  dayEndConunt.getDayEnd().dayAdd();

        return  ResponseEntity.ok(dayEndConunt.getDayEnd());
    }

    @GetMapping("/dayAddtemp")
    public ResponseEntity  dayAddtemp() throws Exception {


        dayEndConunt.getDayEnd().dayAddTemp();

        return  ResponseEntity.ok(dayEndConunt.getDayEnd());
    }

    @GetMapping("/repair")
    public ResponseEntity repair(){

        dayEndConunt.getDayEnd().repairDayEnd();
        return  ResponseEntity.ok(dayEndConunt.getDayEnd());
    }


}
